<?php
declare (strict_types=1);

namespace app\api\controller\v2;

use think\cache\driver\Redis;
use think\captcha\facade\Captcha;
use think\facade\Cache;
use think\facade\Session;
class Code extends BaseController
{

    /**
     * 生成图片验证码
     */

    public function verify()
    {
        //$key = input('key');
        $code = getRandStr(4);
        $img = Captcha::create($code);
       // $setcache = Cache::set(strtolower($code), strtolower($code), 180);
        $redis = new Redis();
        $redis->set(strtolower($code),strtolower($code),180);
        return
            response($img, 900, ['Content-Length' => strlen($img)])->contentType('image/png');
    }

    public function delCache()
    {
        Cache::clear();
    }
}
